"use strict";
const superagent = require('superagent');
const moment = require('moment');

let TEST_DOMAIN = 'http://localhost:3014';

const designVideoUniTest = (function () {

    function designVideoUniTest() {

    }

    /*
    * 设置当前测试用例执行的环境
    * */
    designVideoUniTest.setTestDomain = function (domain) {
        TEST_DOMAIN = domain;
    };

    /**
     * 获取视频模板详情
     *
     * @author mk
     * @date 2018-06-04
     *
     * @param {Object} param   测试参数
     * @param {String} token     令牌
     * @param {String} page_num   当前页
     * @param {Number} page_size  没页容量
     * @param {Function} callback
     */
    designVideoUniTest.getDesignList = function (param,callback) {
        let url = TEST_DOMAIN + '/v1/designs/videos/getDesignList';
        let para = {
            token : param.token,
            page_num : param.page_num,
            page_size : param.page_size
        };
        superagent.post(url)
            .send(para)
            .end(function (error, result) {
                if (error || !result) {
                    if(callback) callback(error || '请求失败');
                    return;
                }
                let response = JSON.parse(result.text);
                if (!response || response.code != 10000) {
                    if (callback) callback(response.msg || '请求失败');
                    return;
                }
                if (callback) callback(null, response.data);
            });
    };

    /**
     * 查询token
     *
     * @author mk
     * @date 2018-06-05
     *
     * @param {Object} param        测试参数
     * @param {String} token         令牌
     * @param {String} design_id    模板的唯一标识
     * @param {Function} callback
     */
    designVideoUniTest.getDesignContent = function (param, callback) {
        let url = TEST_DOMAIN + '/v1/designs/videos/getDesignContent';
        let para = {
            token : param.token,
            design_id : param.design_id
        };
        superagent.post(url)
            .send(para)
            .end(function (error, result) {
                if (error || !result) {
                    if(callback) callback(error || '请求失败');
                    return;
                }
                let response = JSON.parse(result.text);
                if (!response || response.code != 10000) {
                    if (callback) callback(response.msg || '请求失败');
                    return;
                }
                if (callback) callback(null, response.data);
            });
    };


    /**
     *GetDesignList正确参数
     */
    designVideoUniTest.designVideoGetDesignListTestCase1 = function (callback) {
        let param = {
            token : "101002080503010120AVWB1HT3DI9RP3LJ24T38FXFOW1P6LGACWRLFB06020C5FB6CCCB060C0D8E5DDC9EA43IWJ6X1QUBJOU7IJ9XQALG932W5III7HFMSAXACHXX",
            page_num : 0,
            page_size : 12
        };
        designVideoUniTest.getDesignList(param,function (err,data) {
            return callback(err,JSON.stringify(data));
        });
    };

    /**
     *GetDesignList错误参数
     */
    designVideoUniTest.designVideoGetDesignListTestCase2 = function (callback) {
        let param = {
            token : "13246",
            page_num : 0,
            page_size : 12
        };
        designVideoUniTest.getDesignList(param,function (err,data) {
            return callback(err,JSON.stringify(data));
        });
    };



    /**
     *GetDesignContent正确参数
     */
    designVideoUniTest.designVideoGetDesignContentTestCase1 = function (callback) {
        let param = {
            token : "101002080503010120AVWB1HT3DI9RP3LJ24T38FXFOW1P6LGACWRLFB06020C5FB6CCCB060C0D8E5DDC9EA43IWJ6X1QUBJOU7IJ9XQALG932W5III7HFMSAXACHXX",
            design_id : 9103,
        };
        designVideoUniTest.getDesignContent(param,function (err,data) {
            return callback(err,JSON.stringify(data));
        });
    };

    /**
     *GetDesignContent错误参数
     */
    designVideoUniTest.designVideoGetDesignContentTestCase2 = function (callback) {
        let param = {
            token : "1",
            design_id : 0,
        };
        designVideoUniTest.getDesignContent(param,function (err,data) {
            return callback(err,JSON.stringify(data));
        });
    };

    /**
     *GetDesignContent错误参数
     */
    designVideoUniTest.designVideoGetDesignContentTestCase3 = function (callback) {
        let param = {
            token : "101002080503010120AVWB1HT3DI9RP3LJ24T38FXFOW1P6LGACWRLFB06020C5FB6CCCB060C0D8E5DDC9EA43IWJ6X1QUBJOU7IJ9XQALG932W5III7HFMSAXACHXX",
            design_id : 1,
        };
        designVideoUniTest.getDesignContent(param,function (err,data) {
            return callback(err,JSON.stringify(data));
        });
    };





    return designVideoUniTest;
})();
module.exports = designVideoUniTest;



